package model

import (
	"gorm.io/gorm"
	"medi-reserve/medirpc/medirpc"
)

type Reserve struct {
	gorm.Model
	Name        string `gorm:"type:varchar(30)"`
	ReserveCode int    `gorm:"type:int"`
	WxName      string `gorm:"type:varchar(32)"`
	Tel         int    `gorm:"type:int"`
}

func (r *Reserve) AddReserve(db *gorm.DB) error {
	return db.Debug().Create(&r).Error
}

func (r *Reserve) ReserveShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Find(&r).Error
}

func (r *Reserve) ReserveDel(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).Delete(&r).Error
}
func ReserveList(db *gorm.DB, in *medirpc.ReserveListRequest) []*medirpc.ReserveList {
	var list []*medirpc.ReserveList
	db.Model(&Reserve{}).Scopes(Paginate(int(in.Page), int(in.Size))).Find(&list)
	return list
}
